<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Dell
  Date: 2018/12/19
  Time: 17:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css"  media="all">
</head>
<body margintop="100px">


<br>
<br>
<br>
<form id="passwordForm" name="passwordForm" class="layui-form" action="" method="post">

    <div class="layui-form-item" style="display: none">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-inline">
            <input type="password" name="id" lay-verify="id" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="${admin.adId}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">当前密码</label>
        <div class="layui-input-inline">
            <input type="password" name="oldPassword" lay-verify="oldPassword" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-inline">
            <input type="newPassword" name="newPassword" lay-verify="newPassword" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>



</form>



</body>
<script src="../../js/jquery.min.3.1.0.js"></script>
<script src="../../layuiadmin/layui/layui.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            oldPassword: function(value){
                if(value!=${admin.adPassword}){
                    return '当前密码错误';
                }
            }
            ,newPassword:function (value) {
                if(value==""){
                    return '新密码不能为空！';
                }
            }

        });


        //监听提交
        form.on('submit(demo1)', function(data){
            var index = parent.layer.getFrameIndex(window.name);

            $.ajax({
                url:"/ModifyPasswordServlet",   //请求路径
                datatype:"json",//返回的格式
                data:$("#passwordForm").serialize(), //参数
                type:"post", //什么请求
                success:function (data) { //请求成功以后
                    //AJAX成功以后返回的
                    var obj = eval('(' + data + ')');
                    layer.msg(obj.msg);

                    //延时500ms关闭窗口
                    setTimeout(function () {
                        parent.layer.close(index);
                    }, 500);
                }
            });


            return false;
        });




    });
</script>
</html>
